package com.space.user.domain.info.entity;

import com.space.components.exception.Assert;
import com.space.user.domain.info.valueobject.Account;
import com.space.user.domain.info.valueobject.Nickname;
import com.space.user.domain.info.valueobject.PhoneNumber;
import com.space.user.domain.info.valueobject.UserId;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * @author <a href="mailto:414563035@qq.com">Bedroom</a>
 * @date 2021/4/13 7:20 下午
 */
@Getter
@AllArgsConstructor
@Builder
public class UserInfo {
    private UserId userId;

    private Nickname nickname;

    private PhoneNumber phoneNumber;

    private String avatar;

    private String realName;

    private LocalDateTime createTime;

    private Boolean freezeStatus;

    private LocalDateTime freezeTime;

    private Boolean deleteStatus;

    private LocalDateTime deleteTime;

    private Account account;

    public UserInfo initUserId(UserId userId) {
        if (Objects.isNull(this.userId)) {
            this.userId = userId;
        }
        return this;
    }

    public UserInfo isExist() {
        Assert.notNull(this.userId, "用户不存在");
        return this;
    }

    public UserInfo modifyNickName(Nickname nickname) {
        if (Objects.nonNull(nickname)) {
            this.nickname = nickname;
        }
        return this;
    }

    public UserInfo modifyPhoneNumber(PhoneNumber phoneNumber) {
        if (Objects.nonNull(phoneNumber)) {
            this.phoneNumber = phoneNumber;
        }
        return this;
    }

    public UserInfo linkAccount(Account account) {
        Assert.isTrue(userId != account.getUserId(), "用户和账户不匹配");
        this.account = account;
        return this;
    }
}
